#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

bool is_prime(int n) {
  if (n <= 1) {
    return false;
  }
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  vector<string> digits = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
  string input;
  getline(cin, input);

  vector<string> words;
  string word;
  for (char c : input) {
    if (c == ' ') {
      words.push_back(word);
      word = "";
    } else {
      word += c;
    }
  }
  words.push_back(word);

  if (words.size() != 3 ||
      find(digits.begin(), digits.end(), words[0]) == digits.end() ||
      find(digits.begin(), digits.end(), words[1]) == digits.end() ||
      find(digits.begin(), digits.end(), words[2]) == digits.end()) {
    cout << "Wrong input" << endl;
  } else {
    int n = (distance(digits.begin(), find(digits.begin(), digits.end(), words[0])) * 100) +
            (distance(digits.begin(), find(digits.begin(), digits.end(), words[1])) * 10) +
            (distance(digits.begin(), find(digits.begin(), digits.end(), words[2])));

    for (int i = 1; i < 1000; ++i) {
      if (is_prime(n - i)) {
        cout << n - i << endl;
        break;
      }
      if (is_prime(n + i)) {
        cout << n + i << endl;
        break;
      }
    }
  }

  return 0;
}
